package es.iespuertodelacruz.dai.batallanaval.gui;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

public abstract class GamePanel extends JPanel implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5728886500000255838L;
	private JButton[][] cells;
	private GameConfig gameConfig;
	
	private void setup(Size size) {

		JButton btn;				
		JLabel label;
		cells = new JButton[size.h][size.w];
		
		setLayout(new GridLayout(size.w+1, size.h+1));
		
		add(new JLabel());	// JLabel de la esquina superior izquierda
		for(int i = 0; i < 10; i++) {
			char ch = (char) ('A' + (i));
			label = new JLabel(String.valueOf(ch));
			label.setHorizontalAlignment(SwingConstants.CENTER);			
			add(label);
		}
		
		cells = new JButton[10][10];
		for(int i = 0; i < 10; i++) {
			label = new JLabel(""+(i+1));
			label.setHorizontalAlignment(SwingConstants.CENTER); 			
			add(label);			
			for(int j = 0; j < 10; j++) {
				cells[i][j] = btn = new JButton();
				add(btn);
			}
		}		
	}
	
	public GamePanel(GameConfig gameConfig) {
		
		this.gameConfig = gameConfig;
		setup(gameConfig.getBoardSize());
		
	}
	
	public GameConfig getGameConfig() {
		return gameConfig;
	}

	@Override
	public abstract void actionPerformed(ActionEvent e);

}
